package com.vf.admin.utils.douyin;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/** */

/**
* ��ҳ�Ķ���.
* @author anxiang
* Creation date: 2007-10-9 - ����11:47:26
*/
public class PageReader {
//���Ӷ���
	public static HttpURLConnection conn; 

/** *//**
* ����url����ĳ��ַ�������ط�����.
* ������˵����
* 0~200Ϊ�������������200ΪOK
* ���඼Ϊ����������������μ�w3
* @param urlStr �����ӵ�url�ַ���
*/
public int connect(String urlStr) throws Exception {
URL url = new URL(urlStr); 
conn = (HttpURLConnection) url.openConnection(); 
//System.out.println("������: " + conn.getResponseCode()); 
//�������ĵ�ַ�����ض���
//��ôconn.getURL().toString()��ʾ�����ض����ĵ�ַ
//System.out.println("aaaaa:"+conn.getURL().toString()); 
return conn.getResponseCode(); 
}

/** *//**
* ��ȡ��ҳ������.
* @return ������ҳ������
*/
public String readContents() throws Exception {
BufferedReader in = null; 
StringBuffer sb = new StringBuffer(); 
in = new BufferedReader(new InputStreamReader(conn
.getInputStream())); 

String inputLine; 
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine); 
sb.append("\n"); 
}
return sb.toString(); 
}

/** *//**
* �ж�����.
*/
public void disconnect() {
conn.disconnect(); 
}

/** *//**
* ���Է���
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
PageReader reader = new PageReader(); 
String url = "http://v.douyin.com/Ne8Dav/"; 
reader.connect(url); 
String content = reader.readContents();
content = content.substring(content.indexOf("href=\"")+6, content.lastIndexOf("\">h"));
content = content.replaceAll("&amp;","&");
System.out.println("��ҳ���ݣ�" + content); 
reader.disconnect(); 
}
}
